import { _decorator, Component, Label, Node } from 'cc';
import { AudioMgr, SoundName } from '../Mgr/AudioMgr';
import { UIMgr } from '../Mgr/UIMgr';
import { AssetList, Global } from '../Global';
import { LocalStorageMgr } from '../Mgr/LocalStorageMgr';
import { GAMEDATA } from '../GameScene/GAMEDATA';
const { ccclass, property } = _decorator;

@ccclass('GameEnd')
/**
 * 游戏结束层
 */
export class GameEnd extends Component {

    //本局分数
    @property(Label)
    private ScoreLabel: Label = null;

    /**
     * 更新游戏分数
     */
    public UpdateScore() {
        this.ScoreLabel.string = GAMEDATA.GameScore.toString();

        if (LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.BESTSCORE < GAMEDATA.GameScore) {
            LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.BESTSCORE = GAMEDATA.GameScore;
            LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.COIN += GAMEDATA.GameCoin;
            LocalStorageMgr.Instance.UpdateLocalStroage();
        }
    }

    /**
     * 点击回到首页按钮
     */
    public GoLogin() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        UIMgr.Instance.UdpateScene(AssetList.Scene.LoginScene);
        UIMgr.Instance.HidePop(AssetList.Pop.GAMEEND);
    }

}


